{% extends "base.html" %}

{% block title %}个人资料 - 教育管理系统{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="row">
        <div class="col-md-4">
            <div class="card shadow">
                <div class="card-header bg-primary text-white">
                    <h5 class="card-title mb-0">个人信息</h5>
                </div>
                <div class="card-body">
                    <div class="text-center mb-4">
                        <img src="https://via.placeholder.com/150" class="rounded-circle" alt="头像">
                        <h3 class="mt-3">{{ user.name }}</h3>
                        <p class="text-muted">
                            {% if user_type == 'teacher' %}
                            教师 - {{ user.subject }}
                            {% else %}
                            学生 - {{ user.grade }}
                            {% endif %}
                        </p>
                    </div>
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            邮箱
                            <span class="badge bg-primary rounded-pill">{{ user.email }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            账号类型
                            <span class="badge bg-info rounded-pill">{{ '教师' if user_type == 'teacher' else '学生' }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            注册时间
                            <span class="badge bg-secondary rounded-pill">{{ user.created_at.strftime('%Y-%m-%d') }}</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        
        <div class="col-md-8">
            {% if user_type == 'teacher' %}
            <!-- 教师信息展示 -->
            <div class="card shadow">
                <div class="card-header bg-success text-white">
                    <h5 class="card-title mb-0">我的学生</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>姓名</th>
                                    <th>年级</th>
                                    <th>邮箱</th>
                                    <th>注册时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for student in students %}
                                <tr>
                                    <td>{{ student.id }}</td>
                                    <td>{{ student.name }}</td>
                                    <td>{{ student.grade }}</td>
                                    <td>{{ student.email }}</td>
                                    <td>{{ student.created_at.strftime('%Y-%m-%d') }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            {% else %}
            <!-- 学生信息展示 -->
            <div class="card shadow">
                <div class="card-header bg-info text-white">
                    <h5 class="card-title mb-0">我的课程成绩</h5>
                </div>
                <div class="card-body">
                    {% if course_scores %}
                    <div class="accordion" id="courseAccordion">
                        {% for course_name, scores in course_scores.items() %}
                        <div class="accordion-item">
                            <h2 class="accordion-header" id="heading{{ loop.index }}">
                                <button class="accordion-button {{ 'collapsed' if not loop.first }}" type="button" data-bs-toggle="collapse" data-bs-target="#collapse{{ loop.index }}" aria-expanded="{{ 'true' if loop.first else 'false' }}" aria-controls="collapse{{ loop.index }}">
                                    {{ course_name }}
                                </button>
                            </h2>
                            <div id="collapse{{ loop.index }}" class="accordion-collapse collapse {{ 'show' if loop.first }}" aria-labelledby="heading{{ loop.index }}" data-bs-parent="#courseAccordion">
                                <div class="accordion-body">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-hover">
                                            <thead>
                                                <tr>
                                                    <th>考试次数</th>
                                                    <th>分数</th>
                                                    <th>考试日期</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {% for score in scores %}
                                                <tr>
                                                    <td>第{{ score.test_number }}次</td>
                                                    <td>{{ score.score_value }}</td>
                                                    <td>{{ score.test_date.strftime('%Y-%m-%d') }}</td>
                                                </tr>
                                                {% endfor %}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                    {% else %}
                    <div class="alert alert-info">
                        暂无成绩记录
                    </div>
                    {% endif %}
                </div>
            </div>
            
            <div class="card shadow mt-4">
                <div class="card-header bg-warning">
                    <h5 class="card-title mb-0">指导教师信息</h5>
                </div>
                <div class="card-body">
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            教师姓名
                            <span class="text-primary">{{ user.teacher.name }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            教师科目
                            <span class="text-primary">{{ user.teacher.subject }}</span>
                        </li>
                        <li class="list-group-item d-flex justify-content-between align-items-center">
                            联系邮箱
                            <span class="text-primary">{{ user.teacher.email }}</span>
                        </li>
                    </ul>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 